package controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import model.BoardDAO;

import vo.MemberVO;

public class SignupAction implements Action {
	private static Logger logger = Logger.getLogger(LoginAction.class);

	@Override
	public ActionForward execute(HttpServletRequest request, HttpServletResponse response)
			throws ServletException {
		BoardDAO boardDAO = BoardDAO.getInstance();
		MemberVO memberVO = new MemberVO();
		String path = "";
		
		String userid = request.getParameter("userid");
		String userpass = request.getParameter("userpass");
		String username = request.getParameter("username");
		String useraddr = request.getParameter("useraddr");
		
		memberVO.setUserid(userid);
		memberVO.setUserpass(userpass);
		memberVO.setUsername(username);
		memberVO.setUseraddr(useraddr);
		
		int result = boardDAO.addUserInfo(memberVO);
		logger.debug("result: " +result);
		
		if(result!=0) {
			request.setAttribute("result", username + "님의 회원가입을 축하드립니다.");
			path="/signup/signup_result.jsp";
		} else {
			request.setAttribute("result", "회원가입에 실패 하였습니다.");
			path="/signup/signup_result.jsp";
		}
		return new ActionForward(path, false);
	}
}
